HAL PSSI initialization and configuration functions migration

The goal of this page is to show how to migrate the initialization sequence using STM32CubeMX2:

  • Open STM32CubeMX2 PSSI configuration panel.

  • Configure the HAL SW layer.

  • Configure the main PSSI features.

  • Configure the additional feature configuration of the PSSI if needed.

  • Configure the GPIOs needed by the PSSI.

  • Configure the PSSI DMA(s) if the application requires to use the PSSI in DMA mode.

  • Configure the NVIC if the application requires the PSSI to be used in IT mode.

  • Generate the code.

HAL PSSI configuration panel

Create a new project with the STM32CubeMX2, then start the initialization and the main configuration.

Example Image

Configure the PSSI main features

Configure the PSSI main features.

Example Image

Configure the PSSI additional features

Configure the advanced PSSI features.

Example Image

GPIO configuration

Configure gpio pins.

PSSI GPIO configuration

DMA configuration

Configure the DMA for data reception as needed.

DMA TX configuration

PSSI DMA TX configuration

DMA RX configuration

PSSI DMA RX configuration

NVIC configuration

Configure the NVIC in case of an interrupt.

PSSI NVIC configuration

Generated PSSI initialization and de-initialization sequences

The PSSI initialization sequence is generated in the mx_pssi_init function in the mx_pssi.c file under $YOUR_PROJECT_NAME$/$YOUR_PROJECT_NAME$_SW/generated/STM32Cube_CodeGen.

Related concepts:

STM32CubeMX2 Generated : PSSI initialization and de-initialization sequences

Topic

HAL1 code snippet

HAL2 code snippet

Initialization and configuration sequence

static void MX_PSSI_Init(void)
{


    hpssi.Instance = PSSI;





    hpssi.Init.BusWidth = HAL_PSSI_8LINES;
    hpssi.Init.DataWidth = HAL_PSSI_8BITS;
    hpssi.Init.ClockPolarity = HAL_PSSI_FALLING_EDGE;
    hpssi.Init.ControlSignal = HAL_PSSI_DE_RDY_DISABLE;
    hpssi.Init.DataEnablePolarity = HAL_PSSI_DEPOL_ACTIVE_LOW;
    hpssi.Init.ReadyPolarity = HAL_PSSI_RDYPOL_ACTIVE_LOW;
    if (HAL_PSSI_Init(&hpssi) != HAL_OK)
    {
        Error_Handler();
    }
}

void HAL_PSSI_MspInit(PSSI_HandleTypeDef* hpssi)
{
    GPIO_InitTypeDef GPIO_InitStruct = {0};
    if(hpssi->Instance==PSSI)
    {
        /* Peripheral clock enable */
        __HAL_RCC_DCMI_PSSI_CLK_ENABLE();

        __HAL_RCC_GPIOI_CLK_ENABLE();
        __HAL_RCC_GPIOC_CLK_ENABLE();
        __HAL_RCC_GPIOB_CLK_ENABLE();
        __HAL_RCC_GPIOH_CLK_ENABLE();
        __HAL_RCC_GPIOE_CLK_ENABLE();
        /**PSSI GPIO Configuration
        PI6     ------> PSSI_D6
        PC11     ------> PSSI_D4
        PI5     ------> PSSI_RDY
        PB6     ------> PSSI_D5
        PH12     ------> PSSI_D3
        PI7     ------> PSSI_D7
        PH10     ------> PSSI_D1
        PE0     ------> PSSI_D2
        PH8     ------> PSSI_DE
        PH9     ------> PSSI_D0
        PH5     ------> PSSI_PDCK
        */
        GPIO_InitStruct.Pin = GPIO_PIN_6|GPIO_PIN_5|GPIO_PIN_7;
        GPIO_InitStruct.Mode = GPIO_MODE_AF_PP;
        GPIO_InitStruct.Pull = GPIO_NOPULL;
        GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_LOW;
        GPIO_InitStruct.Alternate = GPIO_AF10_PSSI;
        HAL_GPIO_Init(GPIOI, &GPIO_InitStruct);







        GPIO_InitStruct.Pin = GPIO_PIN_11;
        GPIO_InitStruct.Mode = GPIO_MODE_AF_PP;
        GPIO_InitStruct.Pull = GPIO_NOPULL;
        GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_LOW;
        GPIO_InitStruct.Alternate = GPIO_AF10_PSSI;
        HAL_GPIO_Init(GPIOC, &GPIO_InitStruct);








        GPIO_InitStruct.Pin = GPIO_PIN_6;
        GPIO_InitStruct.Mode = GPIO_MODE_AF_PP;
        GPIO_InitStruct.Pull = GPIO_NOPULL;
        GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_LOW;
        GPIO_InitStruct.Alternate = GPIO_AF10_PSSI;
        HAL_GPIO_Init(GPIOB, &GPIO_InitStruct);












        GPIO_InitStruct.Pin = GPIO_PIN_12|GPIO_PIN_10|GPIO_PIN_8|GPIO_PIN_9
                            |GPIO_PIN_5;
        GPIO_InitStruct.Mode = GPIO_MODE_AF_PP;
        GPIO_InitStruct.Pull = GPIO_NOPULL;
        GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_LOW;
        GPIO_InitStruct.Alternate = GPIO_AF10_PSSI;
        HAL_GPIO_Init(GPIOH, &GPIO_InitStruct);







        GPIO_InitStruct.Pin = GPIO_PIN_0;
        GPIO_InitStruct.Mode = GPIO_MODE_AF_PP;
        GPIO_InitStruct.Pull = GPIO_NOPULL;
        GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_LOW;
        GPIO_InitStruct.Alternate = GPIO_AF10_PSSI;
        HAL_GPIO_Init(GPIOE, &GPIO_InitStruct);
    }
}
hal_pssi_handle_t *mx_pssi_init(void)
{
    hal_pssi_config_t pssi_config;

    if (HAL_PSSI_Init(&hPSSI, HAL_PSSI) != HAL_OK)
    {
        return NULL;
    }

    HAL_RCC_PSSI_EnableClock();
    pssi_config.bus_width_line       = HAL_PSSI_BUS_WIDTH_8LINE;
    pssi_config.data_width_bit       = HAL_PSSI_DATA_WIDTH_8BIT;
    pssi_config.clock_polarity       = HAL_PSSI_CLOCK_POLARITY_RX_FALLING_TX_RISING_EDGE;
    pssi_config.control_signal       = HAL_PSSI_CONTROL_SIGNAL_DE_RDY_DISABLE;
    pssi_config.data_enable_polarity = HAL_PSSI_DATA_ENABLE_POLARITY_LOW;
    pssi_config.ready_polarity       = HAL_PSSI_READY_POLARITY_LOW;

    if (HAL_PSSI_SetConfig(&hPSSI, &pssi_config) != HAL_OK)
    {
        return NULL;
    }

    /* PSSI GPIO Configuration *********************************************************/







    HAL_RCC_GPIOI_EnableClock();
    HAL_RCC_GPIOC_EnableClock();
    HAL_RCC_GPIOB_EnableClock();
    HAL_RCC_GPIOH_EnableClock();
    HAL_RCC_GPIOE_EnableClock();

    hal_gpio_config_t  gpio_config;

    /**
        PSSI GPIO Configuration

        [GPIO Pin] ------> [Signal Name]

        PI6     ------>   PSSI_D6
        PI7     ------>   PSSI_D7
        PI5     ------>   PSSI_RDY
        **/
    gpio_config.mode        = HAL_GPIO_MODE_ALTERNATE;
    gpio_config.output_type = HAL_GPIO_OUTPUT_PUSHPULL;
    gpio_config.pull        = HAL_GPIO_PULL_NO;
    gpio_config.speed       = HAL_GPIO_SPEED_FREQ_LOW;
    gpio_config.alternate   = HAL_GPIO_AF_10;
    HAL_GPIO_Init(HAL_GPIOI, HAL_GPIO_PIN_6 | HAL_GPIO_PIN_7 | HAL_GPIO_PIN_5, &gpio_config);

    /**
        PSSI GPIO Configuration

        [GPIO Pin] ------> [Signal Name]

        PC11    ------>   PSSI_D4
        **/
    gpio_config.mode        = HAL_GPIO_MODE_ALTERNATE;
    gpio_config.output_type = HAL_GPIO_OUTPUT_PUSHPULL;
    gpio_config.pull        = HAL_GPIO_PULL_NO;
    gpio_config.speed       = HAL_GPIO_SPEED_FREQ_LOW;
    gpio_config.alternate   = HAL_GPIO_AF_10;
    HAL_GPIO_Init(HAL_GPIOC, HAL_GPIO_PIN_11, &gpio_config);

    /**
        PSSI GPIO Configuration

        [GPIO Pin] ------> [Signal Name]

        PB6     ------>   PSSI_D5
        **/
    gpio_config.mode        = HAL_GPIO_MODE_ALTERNATE;
    gpio_config.output_type = HAL_GPIO_OUTPUT_PUSHPULL;
    gpio_config.pull        = HAL_GPIO_PULL_NO;
    gpio_config.speed       = HAL_GPIO_SPEED_FREQ_LOW;
    gpio_config.alternate   = HAL_GPIO_AF_10;
    HAL_GPIO_Init(HAL_GPIOB, HAL_GPIO_PIN_6, &gpio_config);

    /**
        PSSI GPIO Configuration

        [GPIO Pin] ------> [Signal Name]

        PH5     ------>   PSSI_PDCK
        PH8     ------>   PSSI_DE
        PH9     ------>   PSSI_D0
        PH10    ------>   PSSI_D1
        PH12    ------>   PSSI_D3
        **/
    gpio_config.mode        = HAL_GPIO_MODE_ALTERNATE;
    gpio_config.output_type = HAL_GPIO_OUTPUT_PUSHPULL;
    gpio_config.pull        = HAL_GPIO_PULL_NO;
    gpio_config.speed       = HAL_GPIO_SPEED_FREQ_LOW;
    gpio_config.alternate   = HAL_GPIO_AF_10;
    HAL_GPIO_Init(HAL_GPIOB, HAL_GPIO_PIN_6 | HAL_GPIO_PIN_8 | HAL_GPIO_PIN_9, &gpio_config);

    /**
        PSSI GPIO Configuration

        [GPIO Pin] ------> [Signal Name]

        PE0     ------>   PSSI_D2
        **/
    gpio_config.mode        = HAL_GPIO_MODE_ALTERNATE;
    gpio_config.output_type = HAL_GPIO_OUTPUT_PUSHPULL;
    gpio_config.pull        = HAL_GPIO_PULL_NO;
    gpio_config.speed       = HAL_GPIO_SPEED_FREQ_LOW;
    gpio_config.alternate   = HAL_GPIO_AF_10;
    HAL_GPIO_Init(HAL_GPIOE, HAL_GPIO_PIN_0, &gpio_config);

    return &hPSSI;
}

Deinitialization sequence

void HAL_PSSI_MspDeInit(PSSI_HandleTypeDef* hpssi)
{
    if(hpssi->Instance==PSSI)
    {
        /* Peripheral clock disable */
        __HAL_RCC_DCMI_PSSI_CLK_DISABLE();

        /**PSSI GPIO Configuration
        PI6     ------> PSSI_D6
        PC11     ------> PSSI_D4
        PI5     ------> PSSI_RDY
        PB6     ------> PSSI_D5
        PH12     ------> PSSI_D3
        PI7     ------> PSSI_D7
        PH10     ------> PSSI_D1
        PE0     ------> PSSI_D2
        PH8     ------> PSSI_DE
        PH9     ------> PSSI_D0
        PH5     ------> PSSI_PDCK
        */
        HAL_GPIO_DeInit(GPIOI, GPIO_PIN_6|GPIO_PIN_5|GPIO_PIN_7);

        HAL_GPIO_DeInit(GPIOC, GPIO_PIN_11);

        HAL_GPIO_DeInit(GPIOB, GPIO_PIN_6);

        HAL_GPIO_DeInit(GPIOH, GPIO_PIN_12|GPIO_PIN_10|GPIO_PIN_8|GPIO_PIN_9
                            |GPIO_PIN_5);

        HAL_GPIO_DeInit(GPIOE, GPIO_PIN_0);
    }
}
void mx_pssi_deinit(void)
{
    (void)HAL_PSSI_DeInit(&hPSSI);

    HAL_RCC_PSSI_Reset();

    HAL_RCC_PSSI_DisableClock();












    /* De-initialize all GPIO pins associated with PSSI */
    HAL_GPIO_DeInit(HAL_GPIOI, HAL_GPIO_PIN_6|HAL_GPIO_PIN_5|HAL_GPIO_PIN_7);

    HAL_GPIO_DeInit(HAL_GPIOB, HAL_GPIO_PIN_6);

    HAL_GPIO_DeInit(HAL_GPIOC, HAL_GPIO_PIN_11);

    HAL_GPIO_DeInit(HAL_GPIOH, HAL_GPIO_PIN_11|HAL_GPIO_PIN_10|HAL_GPIO_PIN_8|HAL_GPIO_PIN_9
                            |HAL_GPIO_PIN_5);

    HAL_GPIO_DeInit(HAL_GPIOE, HAL_GPIO_PIN_0);
}